package example.controller;

import example.common.Result;
import example.entity.Department;
import example.service.IDepartmentService;
import example.service.ILevelService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/api")
public class DepartmentController {

    @Resource
    private IDepartmentService departmentService;

    @Resource
    private ILevelService levelService;

    @PostMapping("/sys/login")
    public Result getDepartmentInfo(@RequestBody Department department) {
        return departmentService.verifyDepartmentInfo(department);
    }

    @GetMapping("/sys/profile")
    public Result getUserInfo(HttpServletRequest request) {
        String token = request.getHeader("Authorization");
        return departmentService.getUserInfo(token);
    }

    @GetMapping("/company/department/{id}")
    public Result deleteDepartment(@PathVariable("id") Long departmentId) {
        return departmentService.deleteDepartment(departmentId);
    }
    @PostMapping("/department/getToUpdate")
    public Result getDepartmentDetailToUpdate(@RequestBody Department department)
    {
      return departmentService.getDepartmentDetailToUpdate(department.getName());
    }
    @PostMapping("/department/update")
    public Result updateDepartmentDetail(@RequestBody Department department)
    {
      return departmentService.updateDepartmentDetail(department);
    }

    @GetMapping("/company/department")
    public Result getDepartmentList() {
        return departmentService.getDepartmentList();
    }

    @GetMapping("/sys/user/simple")
    public Result getLevelList() {
        return levelService.getLevelList();
    }

    @PostMapping("/company/department")
    public Result addDepartment(@RequestBody Department department) {
        return departmentService.addDepartment(department);
    }

    @GetMapping("/dep/names")
    public Result listDepartmentNames() {
        return departmentService.listDepartmentNames();
    }

    @GetMapping("/dep/lis/{id}")
    public Result listDepNames(@PathVariable("id") Long departmentId) {
        return departmentService.listDepNames(departmentId);
    }
}
